<template>
  <div>
    <div class="app-container dealerdetail_container">
      <div class="page_header">测量工单详情</div>
      <el-tabs v-model="tabTypeInfo" type="card">
        <el-tab-pane label="测量信息" name="testInfo"></el-tab-pane>
      </el-tabs>
      <div class="detail_page" v-show="tabTypeInfo === 'testInfo'">
        <div class="row">
          <div class="detail_label">预约单号:</div>
          <div class="detail_value">{{formData.orderCode}}</div>
        </div>
        <div class="row">
          <div class="detail_label">预约时间:</div>
          <div class="detail_value">{{formData.orderDate}}</div>
        </div>
        <div class="row">
          <div class="detail_label">用户姓名:</div>
          <div class="detail_value">{{formData.userName}}</div>
        </div>
        <div class="row">
          <div class="detail_label">联系电话:</div>
          <div class="detail_value">{{formData.phoneNumber}}</div>
        </div>
        <div class="row">
          <div class="detail_label">详细地址:</div>
          <div class="detail_value">{{formData.userProvince}}{{formData.userCity}}{{formData.userArea}}{{formData.address}}</div>
        </div>
        <div class="row">
          <div class="detail_label">预估面积:</div>
          <div class="detail_value">{{formData.estimatedArea}}</div>
        </div>
        <div class="row">
          <div class="detail_label">备注:</div>
          <div class="detail_value">{{formData.orderRemark}}</div>
        </div>


        <div class="row">
          <el-tabs v-model="activeName" style="width: 50%">
            <el-tab-pane label="防水" name="first">


              <div v-for="(water,index) of formData.measure.waterproofJson.datalist" :key="index">
                <div class="row">
                  <div class="detail_label">测量位置:</div>
                  <div class="detail_value" >
                    <el-input v-model="water.optName" placeholder="请输入内容" style=""></el-input>
                    <el-button v-if="index==0" type="primary" @click="handleOptAdd(formData.measure.waterproofJson.datalist)" >添加位置</el-button>
                  </div>
                </div>
                <div v-for="(child,index) of water.child" :key="index">
                  <el-form :inline="true" class="demo-form-inline">
                      <el-form-item>
                        <el-input v-model="child.name"   style="width: 80px"></el-input>
                      </el-form-item>
                      <el-form-item>
                        <el-input @change="handleWidthCountChange($event,child,formData.measure.waterproofJson.datalist,'fs',water)" v-model="child.width"  style="width: 80px"></el-input>
                      </el-form-item>
                      <el-form-item>
                        *
                      </el-form-item>
                      <el-form-item>
                        <el-input @change="handleHeightCountChange($event,child,formData.measure.waterproofJson.datalist,'fs',water)" v-model="child.height"  style="width: 80px"></el-input>
                      </el-form-item>
                      <el-form-item>
                        =
                      </el-form-item>
                      <el-form-item>
                        <el-input  v-model="child.area" style="width: 80px"></el-input>
                      </el-form-item>
                    <el-form-item>
                      <el-button @click="handleChildAdd(water.child)" v-if="index==0" type="primary" >添加</el-button>
                    </el-form-item>
                  </el-form>
                </div>
                <div class="row">
                  <div class="detail_label">测量面积:</div>
                  <div class="detail_value">
                    {{water.czarea}}
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="detail_label">防水总面积:</div>
                <div class="detail_value">
                    {{formData.measure.waterproofJson.zarea}}
                </div>
              </div>
              <div class="row">
                <div class="detail_label">选择方案:</div>
                <div class="detail_value">
                  <el-select @change="fsschemeChange" v-model="formData.measure.waterproofJson.schemeaId" placeholder="请选择">
                    <el-option
                      v-for="item in fsschemeList"
                      :key="item.schemeId"
                      :label="item.schemeName"
                      :value="item.schemeId">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="row">
                  {{formData.measure.waterproofJson.schemeaTxt}}
              </div>
              <div class="row">
                <div class="detail_label">防水总费用:</div>
                <div class="detail_value">
                  {{formData.measure.waterproofJson.zprice}}
                </div>
              </div>


            </el-tab-pane>
            <el-tab-pane label="给排水" name="second">

              <div v-for="(water,index) of formData.measure.drainageJson.datalist" :key="index">
                <div class="row">
                  <div class="detail_label">测量位置:</div>
                  <div class="detail_value">
                    <el-input v-model="water.optName" placeholder="请输入内容"></el-input>
                    <el-button v-if="index==0" type="primary" @click="handleOptAdd(formData.measure.drainageJson.datalist)" >添加位置</el-button>
                  </div>

                </div>
                <div v-for="(child,index) of water.child" :key="index">
                  <el-form :inline="true" class="demo-form-inline">
                    <el-form-item>
                      <el-input v-model="child.name"   style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-input @change="handleWidthCountChange($event,child,formData.measure.drainageJson.datalist,'jps',water)" v-model="child.width"  style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      *
                    </el-form-item>
                    <el-form-item>
                      <el-input @change="handleHeightCountChange($event,child,formData.measure.drainageJson.datalist,'jps',water)" v-model="child.height"  style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      =
                    </el-form-item>
                    <el-form-item>
                      <el-input  v-model="child.area" style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button @click="handleChildAdd(water.child)" v-if="index==0" type="primary" >添加</el-button>
                    </el-form-item>
                  </el-form>
                </div>
                <div class="row">
                  <div class="detail_label">测量面积:</div>
                  <div class="detail_value">
                    {{water.czarea}}
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="detail_label">给排水总面积:</div>
                <div class="detail_value">
                  {{formData.measure.drainageJson.zarea}}
                </div>
              </div>
              <div class="row">
                <div class="detail_label">选择方案:</div>
                <div class="detail_value">
                  <el-select @change="jpsschemeChange" v-model="formData.measure.drainageJson.schemeaId" placeholder="请选择">
                    <el-option
                      v-for="item in jpsschemeList"
                      :key="item.schemeId"
                      :label="item.schemeName"
                      :value="item.schemeId">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="row">
                {{formData.measure.drainageJson.schemeaTxt}}
              </div>
              <div class="row">
                <div class="detail_label">给排总水费用:</div>
                <div class="detail_value">
                  {{formData.measure.drainageJson.zprice}}
                </div>
              </div>


            </el-tab-pane>
            <el-tab-pane label="电工" name="third">
              <div v-for="(water,index) of formData.measure.electricianJson.datalist" :key="index">
                <div class="row">
                  <div class="detail_label">测量位置:</div>
                  <div class="detail_value">
                    <el-input v-model="water.optName" placeholder="请输入内容"></el-input>
                    <el-button v-if="index==0" type="primary" @click="handleOptAdd(formData.measure.electricianJson.datalist)" >添加位置</el-button>
                  </div>
                </div>
                <div v-for="(child,index) of water.child" :key="index">
                  <el-form :inline="true" class="demo-form-inline">
                    <el-form-item>
                      <el-input v-model="child.name"   style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-input @change="handleWidthCountChange($event,child,formData.measure.electricianJson.datalist,'dg',water)" v-model="child.width"  style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      *
                    </el-form-item>
                    <el-form-item>
                      <el-input @change="handleHeightCountChange($event,child,formData.measure.electricianJson.datalist,'dg',water)" v-model="child.height"  style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      =
                    </el-form-item>
                    <el-form-item>
                      <el-input  v-model="child.area" style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button @click="handleChildAdd(water.child)" v-if="index==0" type="primary" >添加</el-button>
                    </el-form-item>
                  </el-form>
                </div>
                <div class="row">
                  <div class="detail_label">测量面积:</div>
                  <div class="detail_value">
                    {{water.czarea}}
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="detail_label">电工总面积:</div>
                <div class="detail_value">
                  {{formData.measure.electricianJson.zarea}}
                </div>
              </div>
              <div class="row">
                <div class="detail_label">选择方案:</div>
                <div class="detail_value">
                  <el-select @change="dgschemeChange" v-model="formData.measure.electricianJson.schemeaId" placeholder="请选择">
                    <el-option
                      v-for="item in dgschemeList"
                      :key="item.schemeId"
                      :label="item.schemeName"
                      :value="item.schemeId">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="row">
                {{formData.measure.electricianJson.schemeaTxt}}
              </div>
              <div class="row">
                <div class="detail_label">电工总费用:</div>
                <div class="detail_value">
                  {{formData.measure.electricianJson.zprice}}
                </div>
              </div>



            </el-tab-pane>
            <el-tab-pane label="其他" name="fourth">
              <div v-for="(water,index) of formData.measure.otherJson.datalist" :key="index">
                <div class="row">
                  <div class="detail_label">测量位置:</div>
                  <div class="detail_value">
                    <el-input v-model="water.optName" placeholder="请输入内容"></el-input>
                    <el-button v-if="index==0" type="primary" @click="handleOptAdd(formData.measure.otherJson.datalist)" >添加位置</el-button>
                  </div>
                </div>
                <div v-for="(child,index) of water.child" :key="index">
                  <el-form :inline="true" class="demo-form-inline">
                    <el-form-item>
                      <el-input v-model="child.name"   style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-input @change="handleWidthCountChange($event,child,formData.measure.otherJson.datalist,'qt',water)" v-model="child.width"  style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      *
                    </el-form-item>
                    <el-form-item>
                      <el-input @change="handleHeightCountChange($event,child,formData.measure.otherJson.datalist,'qt',water)" v-model="child.height"  style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      =
                    </el-form-item>
                    <el-form-item>
                      <el-input  v-model="child.area" style="width: 80px"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button @click="handleChildAdd(water.child)" v-if="index==0" type="primary" >添加</el-button>
                    </el-form-item>
                  </el-form>
                </div>
                <div class="row">
                  <div class="detail_label">测量面积:</div>
                  <div class="detail_value">
                    {{water.czarea}}
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="detail_label">其他总面积:</div>
                <div class="detail_value">
                  {{formData.measure.otherJson.zarea}}
                </div>
              </div>

              <div class="row">
                <div class="detail_label"></div>
                <div class="detail_value">
                  <el-button type="primary" @click="schemeAdd()">添加方案</el-button>
                </div>
              </div>


              <div v-for="(child,index) of formData.measure.otherJson.schemeList" :key="'scheme'+index">
                <div class="row">
                  <div class="detail_label">选择方案:</div>
                  <div class="detail_value">
                    <el-select @change="qtschemeChange(child)" v-model="child.schemeaId" placeholder="请选择">
                      <el-option
                        v-for="item in qtschemeList"
                        :key="item.schemeId"
                        :label="item.schemeName"
                        :value="item.schemeId"
                        >
                      </el-option>
                    </el-select>
                  </div>
                </div>
                <div class="row">
                  {{child.schemeaTxt}}
                </div>
              </div>

              <div class="row">
                <div class="detail_label">其他总费用:</div>
                <div class="detail_value">
                  {{formData.measure.otherJson.zprice}}
                </div>
              </div>

            </el-tab-pane>
          </el-tabs>
        </div>
        <div class="row">
          <div class="detail_label">订单总费用:</div>
          <div class="detail_value">{{formData.measure.allAmount}}</div>
        </div>
        <div class="row" v-if="formData.measure.measurerStatus=='2'||formData.measure.measurerStatus=='1'">
          <div class="detail_label">支付方式:</div>
          <div class="detail_value">
            <el-radio-group @change="payTypeDataChange" :disabled="payTypeData.payType=='1'" v-model="formData.payType">
              <el-radio  :label="1">一次性支付</el-radio>
              <el-radio  :label="2">分期支付</el-radio>
            </el-radio-group>
          </div>
        </div>
        <div class="row">
          <el-table
            :data="formData.measure.periodList"
            style="width: 100%">
            <el-table-column
              prop="payName"
              label="期数"
              width="180">
            </el-table-column>
            <el-table-column
              prop="payRate"
              label="货款比例(%)"
              width="180">
            </el-table-column>
            <el-table-column
              prop="paymentAmount"
              label="金额">
            </el-table-column>
            <el-table-column
              label="操作">
              <template slot-scope="scope">
                <el-button v-if="scope.row.paymentStatus=='未支付'" @click="addPayment(scope.row)"  size="mini" type="text" >待支付</el-button>
                <el-button v-if="scope.row.paymentStatus=='已支付'"  size="mini" type="text" >已支付</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="row" >
          <el-button v-if="formData.measure.measurerStatus=='2'||formData.measure.measurerStatus=='1'" type="primary" :disabled="pending" @click="submitForm('3')">确认订单</el-button>
          <el-button v-if="formData.measure.measurerStatus=='2'||formData.measure.measurerStatus=='1'" type="primary" :disabled="pending" @click="submitForm('2')">保存草稿</el-button>
          <el-button type="primary" :disabled="pending" @click="psyBack()">模拟支付成功</el-button>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import { getTestOrderById,getTestOrderScheme,addMeasure } from '@/api/order/order'
  import { areaPrice,orderPayBack,addPayment } from '@/api/test/order'
  export default {
    name: 'Testorder',
    components: {},
    data() {
      return {
        tabTypeInfo: 'testInfo',
        activeName:'first',
        formData: {
          orderCode:'',
          userName:'',
          orderDate:'',
          phoneNumber:'',
          userProvince:'',
          userCity:'',
          userArea:'',
          address:'',
          estimatedArea:'',
          orderId:'',
          orderRemark:'',
          agreeMeasurer:'',//是否同意
          houseNumberJson:'',//门牌号图片
          measurerMark:'我是备注',//备注信息
          measurerDate:'',//测量时间
          autographJson:'',//签名图片
          payType:'',
          orderDetail:{
            dealerId:''
          },
          measure:{
            //防水数据
            waterproofJson:{
                 datalist:[{
                      optName:'',
                      child:[{
                        name:'',
                        width:0,
                        height:0,
                        area:0
                      }],
                     czarea:0
                  }],
                 zarea:0,//总面积
                 schemeaId:undefined,
                 schemeaTxt:'',
                 schemeaPrice:0,//方案单价
                 zprice:0,//总费用
                 schemea:undefined
            },
            //给排水数据
            drainageJson:{
                datalist:[{
                  optName:'',
                  child:[{
                    name:'',
                    width:0,
                    height:0,
                    area:0
                  }],czarea:0
                }],
                zarea:0,//总面积
                schemeaId:undefined,
                schemeaTxt:'',
                schemeaPrice:0,//方案单价
                zprice:0,//总费用
                schemea:undefined
            },
            //电工数据
            electricianJson:{
                datalist:[{
                  optName:'',
                  child:[{
                    name:'',
                    width:0,
                    height:0,
                    area:0
                  }]
                  ,czarea:0
                }],
                zarea:0,//总面积
                schemeaId:undefined,
                schemeaTxt:'',
                schemeaPrice:0,//方案单价
                zprice:0,//总费用
                schemea:undefined
            },
            //其他数据
            otherJson:{
              datalist:[{
                optName:'',
                child:[{
                  name:'',
                  width:0,
                  height:0,
                  area:0
                }]
                ,czarea:0
              }],
              zarea:0,//总面积
              zprice:0,//总费用
              schemeList:[{
                schemeaId:undefined,
                schemeaTxt:'',
                schemeaPrice:0,//方案单价
                schemea:undefined,
              }]
            },
            allAmount:0//总订单费用
            ,
            periodList:[{
              orderId:'',
              payName:'',
              sort:'',
              payRate:'',
              paymentAmount:''
            }]
          }
        },
        loading:true,
        pending:false,
        //防水方案列表
        fsschemeList:[],
        //电工方案列表
        dgschemeList:[],
        //给排水方案列表
        jpsschemeList:[],
        //其他方案列表
        qtschemeList:[],
        //是否可以分期
        payTypeData:{
          payType:'1',
          payTypeJson:{}
        },
        //确认订单后支付返回订单信息
        payBackObject:undefined
      }
    },
    computed: {
      ID() {
        this.formData.orderId= this.$route.query.id;
        return this.formData.orderId;
      }
    },
    async created() {
    },
    async mounted() {
      if (this.ID){
        this.getOrderById();
      }
    },
    methods: {
      //初始化字典
      async initDictsOptions(dicts, listProps) {
        try {
          const res = await this.getDicts(dicts)
          if (res.code === 200) {
            this[listProps] = res.data.map((per) => ({
              label: per.dictLabel,
              value: per.dictValue
            }))
          }
        } catch (error) {
          console.log(error)
        }
      },
      //宽度改变（通用）
      handleWidthCountChange(e,obj,list,type,water){
        if (e !== undefined && obj.height) {
          obj.area = e * obj.height
        } else {
          obj.area = 0
        }
        this.handleSumChange(list,type,water);
      },
      //高度改变（通用）
      handleHeightCountChange(e,obj,list,type,water){
        if (e !== undefined && obj.width) {
          obj.area = e * obj.width
        } else {
          obj.area = 0
        }
        this.handleSumChange(list,type,water);
      },
      //计算总面积(通用)
      handleSumChange(list,type,water){
        let sum=0;
        list.forEach(function (item,index) {
          item.child.forEach(function (itm,inex) {
            sum+=itm.area
          });
        })
        let count=0
        water.child.forEach(function (item,indx) {
          count+=item.area;
        })
        water.czarea=count;
        if(type=='fs'){
          this.formData.measure.waterproofJson.zarea=sum;
          //计算总费用
          this.fszpriceSum()
        }else if(type=='jps'){
          this.formData.measure.drainageJson.zarea=sum;
          //计算总费用
          this.jpszpriceSum()
        }else if(type=='dg'){
          this.formData.measure.electricianJson.zarea=sum;
          //计算总费用
          this.dgzpriceSum()
        }
        else if(type=='qt'){
          this.formData.measure.otherJson.zarea=sum;
          //计算总费用
          this.qtzpriceSum()
        }

      },
      //添加面积项（通用）
      handleChildAdd(e){
        e.push({
          name:'',
          width:0,
          height:0,
          area:0
        })
      },
      //添加位置（通用）
      handleOptAdd(e){
        e.push({
          optName:'',
          child:[{
            name:'',
            width:0,
            height:0,
            area:0
          }]
          ,czarea:0
        })
      },
      //防水方案切换
      fsschemeChange(obj){
        let txt='';
        const $this=this;
        this.fsschemeList.forEach(function (item,index) {
          if(item.schemeId==obj){
              $this.formData.measure.waterproofJson.schemeaPrice=item.schemePrice;
              txt="1.每平方"+item.schemePrice+"元";
              item.schemeProducts.forEach(function (it,inex) {
                txt+='2.材料（'+it.schemeProductName+",";
              });
              txt+="）";
              $this.formData.measure.waterproofJson.schemeaTxt=txt;
              $this.formData.measure.waterproofJson.schemea=item;
          }
        });
        this.fszpriceSum();
      },
      //防水总费用计算
      fszpriceSum(){
        this.formData.measure.waterproofJson.zprice=(this.formData.measure.waterproofJson.zarea==undefined?0: this.formData.measure.waterproofJson.zarea) *
          (this.formData.measure.waterproofJson.schemeaPrice==undefined?0:this.formData.measure.waterproofJson.schemeaPrice);
        this.orderzprice();
      },
      //给排水方案切换
      jpsschemeChange(obj){
        let txt='';
        const $this=this;
        this.jpsschemeList.forEach(function (item,index) {
          if(item.schemeId==obj){
            $this.formData.measure.drainageJson.schemeaPrice=item.schemePrice;
            txt="1.每平方"+item.schemePrice+"元";
            item.schemeProducts.forEach(function (it,inex) {
              txt+='2.材料（'+it.schemeProductName+",";
            });
            txt+="）";
            $this.formData.measure.drainageJson.schemeaTxt=txt;
            $this.formData.measure.drainageJson.schemea=item;
          }
        });
        this.jpszpriceSum();
      },
      //给排水总费用计算
      jpszpriceSum(){
        this.formData.measure.drainageJson.zprice=(this.formData.measure.drainageJson.zarea==undefined?0: this.formData.measure.drainageJson.zarea) *
          (this.formData.measure.drainageJson.schemeaPrice==undefined?0:this.formData.measure.drainageJson.schemeaPrice);
        this.orderzprice();
        },
      //电工方案切换
      dgschemeChange(obj){
        let txt='';
        const $this=this;
        this.dgschemeList.forEach(function (item,index) {
          if(item.schemeId==obj){
            $this.formData.measure.electricianJson.schemeaPrice=item.schemePrice;
            txt="1.每平方"+item.schemePrice+"元";
            item.schemeProducts.forEach(function (it,inex) {
              txt+='2.材料（'+it.schemeProductName+",";
            });
            txt+="）";
            $this.formData.measure.electricianJson.schemeaTxt=txt;
            $this.formData.measure.electricianJson.schemea=item;
          }
        });
        this.dgzpriceSum();
      },
      //电工总费用计算
      dgzpriceSum(){
        this.formData.measure.electricianJson.zprice=(this.formData.measure.electricianJson.zarea==undefined?0: this.formData.measure.electricianJson.zarea) *
          (this.formData.measure.electricianJson.schemeaPrice==undefined?0:this.formData.measure.electricianJson.schemeaPrice);
        this.orderzprice();
      },
      //其他方案切换
      qtschemeChange(obj){
        let txt='';
        const $this=this;
        this.qtschemeList.forEach(function (item,index) {
          if(item.schemeId==obj.schemeaId){
            obj.schemeaPrice=item.schemePrice;
            txt="1.每平方"+item.schemePrice+"元";
            item.schemeProducts.forEach(function (it,inex) {
              txt+='2.材料（'+it.schemeProductName+",";
            });
            txt+="）";
            obj.schemeaTxt=txt;
            obj.schemea=item;
          }
        });
        this.qtzpriceSum();
      },
      schemeAdd(){
        this.formData.measure.otherJson.schemeList.push({
          schemeaId:undefined,
          schemeaTxt:'',
          schemeaPrice:0,//方案单价
          schemea:undefined,
        });
      },
      //其他总费用计算
      qtzpriceSum(){
        //计算方案价钱
        let sum=0;
        const $this=this;
        this.formData.measure.otherJson.schemeList.forEach(function (item,index) {
          sum+=($this.formData.measure.otherJson.zarea==undefined?0: $this.formData.measure.otherJson.zarea) * (item.schemeaPrice==undefined?0:item.schemeaPrice);
        })
        this.formData.measure.otherJson.zprice=sum;
        this.orderzprice();
      },
      //订单总费用计算
      orderzprice(){
        //计算总价钱
        this.formData.measure.allAmount=
          //防水
          this.formData.measure.waterproofJson.zprice+
          //给排水
          this.formData.measure.drainageJson.zprice+
          //电工
          this.formData.measure.electricianJson.zprice+
          //其他
          this.formData.measure.otherJson.zprice;
      },
      //支付方式改变
      payTypeDataChange(obj){
        this.formData.measure.periodList=[];
        if('2'==obj){
          //校验是否可以进行分期
          if(this.payTypeData.payType!='2'){
            this.msgError("当前订单不准许分期！")
            this.formData.payType='1';
            return;
          }
          const $this=this;
          this.payTypeData.payTypeJson.forEach(function (item,index) {
            $this.formData.measure.periodList.push({
              orderId:'',
              payName:item.name,
              sort:index,
              payRate:item.value,
              paymentAmount:$this.formData.measure.allAmount*(item.value/100)
            });
          })
        }else{
          this.formData.measure.periodList.push({
            orderId:'',
            payName:'第一期',
            sort:1,
            payRate:'100',
            paymentAmount:this.formData.measure.allAmount
          });
        }
      },
      //获取订单详情
      async getOrderById(){
        const res = await getTestOrderById(this.ID)
        const formData=this.formData;
        this.formData={...formData,...res.data};
        //防水
        if(this.formData.measure.waterproofJson==undefined){
          this.formData.measure.waterproofJson={datalist:[{optName:"",child:[{name:"",width:0,height:0,area:0}],czarea:0}],zarea:0,schemeaId:undefined,schemeaPrice:0,zprice:0}
        }else{
          this.formData.measure.waterproofJson=JSON.parse(this.formData.measure.waterproofJson);
        }
        //给排水
        if(this.formData.measure.drainageJson==undefined){
          this.formData.measure.drainageJson={datalist:[{optName:"",child:[{name:"",width:0,height:0,area:0}],czarea:0}],zarea:0,schemeaId:undefined,schemeaPrice:0,zprice:0}
        }else{
          this.formData.measure.drainageJson=JSON.parse(this.formData.measure.drainageJson);
        }
        //电工
        if(this.formData.measure.electricianJson==undefined){
          this.formData.measure.electricianJson={datalist:[{optName:"",child:[{name:"",width:0,height:0,area:0}],czarea:0}],zarea:0,schemeaId:undefined,schemeaPrice:0,zprice:0}
        }else{
          this.formData.measure.electricianJson=JSON.parse(this.formData.measure.electricianJson);
        }
        //其他
        if(this.formData.measure.otherJson==undefined){
          this.formData.measure.otherJson={datalist:[{optName:"",child:[{name:"",width:0,height:0,area:0}],czarea:0}],zarea:0,zprice:0,schemeList:[{
              schemeaId:undefined,
              schemeaTxt:'',
              schemeaPrice:0,
              schemea:undefined,
            }]}
        }else{
          this.formData.measure.otherJson=JSON.parse(this.formData.measure.otherJson);
        }
        if(this.formData.measure.periodList){
          this.payBackObject=this.formData.measure.periodList;
        }
        //获取方案
        this.getTestOrderScheme();
      },
      //获取方案
      async getTestOrderScheme(){
        const res = await getTestOrderScheme({
          province:this.formData.userProvince,
          city:this.formData.userCity,
          area:this.formData.userArea,
          dealerId:this.formData.orderDetail.dealerId
        })
        const listData =res.data;
        const $this=this;
        if(listData){
          listData.forEach(function (item,index) {
              if(item.schemeFun=='1'){
                $this.fsschemeList.push(item);
              }else if(item.schemeFun=='2'){
                $this.dgschemeList.push(item);
              }else if(item.schemeFun=='3'){
                $this.jpsschemeList.push(item);
              }else {
                $this.qtschemeList.push(item)
              }
          });
        }
        //获取是否可以分期
        const resp= await areaPrice({
          province:this.formData.userProvince,
          city:this.formData.userCity,
          area:this.formData.userArea
        })
        if(resp.data){
          this.payTypeData=resp.data;
        }
      },
      async addPayment(row){
        //发起重新支付
        const res = await addPayment({orderCode:row.payOrderCode});
        if (res.code === 200) {
          this.msgSuccess(res.msg)
        }
      },
      async psyBack(){
        console.log(this.payBackObject);
        if(!this.payBackObject) {
          this.msgError("请先确认订单后提交");
          return;
        }
        try {
          this.pending = true
          let payCode="";
          this.payBackObject.forEach(function (item,index) {
              if(item.type!='定金'&&item.paymentStatus!='已支付'){
                payCode=item.payOrderCode;
              }
          })
          const par={ payCode:payCode}
          const res = await orderPayBack(par);
          if (res.code === 200) {
            this.msgSuccess(res.msg)
          }
        } catch (error) {
          console.log(error)
        }
        this.pending = false
      },
      async submitForm(status) {
        try {
            this.pending = true
            const datas={
              orderId:this.formData.orderId,
              orderCode:this.formData.orderCode,
              waterproofJson:this.formData.measure.waterproofJson,
              drainageJson:this.formData.measure.drainageJson,
              electricianJson:this.formData.measure.electricianJson,
              otherJson:this.formData.measure.otherJson,
              agreeMeasurer:'1',
              houseNumberJson:[ {
                "name": "20201109/5234306172d043808b1ec8a5f0b8bea4.jpg",
                "url": "https://jiazhuang2020.oss-cn-hangzhou.aliyuncs.com/20201109/5234306172d043808b1ec8a5f0b8bea4.jpg"
              }],
              measurerMark:'备注',
              measurerDate:'',
              autographJson:[ {
                "name": "20201109/5234306172d043808b1ec8a5f0b8bea4.jpg",
                "url": "https://jiazhuang2020.oss-cn-hangzhou.aliyuncs.com/20201109/5234306172d043808b1ec8a5f0b8bea4.jpg"
              }],
              allAmount:this.formData.measure.allAmount,
              period:'',
              measurerStatus:status,
              periodList:this.formData.measure.periodList
            }
            console.log(JSON.stringify(datas));
            const res = await addMeasure(datas);
            if (res.code === 200) {
               this.msgSuccess(res.msg)
                this.payBackObject=res.data;
            }
        } catch (error) {
          console.log(error)
        }
        this.pending = false
      }
    }
  }
</script>

<style lang='scss'>
  .dealerdetail_container {
    .detail_page {
      .detail_label {
        width: 150px;
      }
    }
  }
</style>




